#include "dialog.h"
#include "ui_dialog.h"
#include"QLayout"
Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dialog)
{
    ui->setupUi(this);
    QGridLayout*layout=new QGridLayout(this);

    geometryname=new QLabel(QString("geometry()："),this);
    geometryvalue=new QLabel(this);
    widthname=new QLabel(QString("width()："),this);
    widthvalue=new QLabel(this);
    heghtname=new QLabel(QString("height()："),this);
    heightvalue=new QLabel(this);
    labelrect=new QLabel(QString("rect()："),this);
    rectvalue=new QLabel(this);
    sizename=new QLabel(QString("size()："),this);
    sizevalue=new QLabel(this);
    layout->addWidget(geometryname,0,0);
    layout->addWidget(geometryvalue,0,1);
    layout->addWidget(widthname,1,0);
    layout->addWidget(widthvalue,1,1);
    layout->addWidget(heghtname,2,0);
    layout->addWidget(heightvalue,2,1);
    layout->addWidget(labelrect,3,0);
    layout->addWidget(rectvalue,3,1);
    layout->addWidget(sizename,4,0);
    layout->addWidget(sizevalue,4,1);
    this->setLayout(layout);
    update();
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::moveEvent(QMoveEvent *ev)
{(void)ev;
 update();
}

void Dialog::resizeEvent(QResizeEvent *ev)
{ (void)ev;
   update();
}

void Dialog::update()
{   //对于父窗口而言的对话框geometry信息
    QString str1,str2,str3,str4;
    geometryvalue->setText(str1.setNum(geometry().x())+","+str2.setNum(geometry().y())+","+str3.setNum(geometry().width())+","+str4.setNum(geometry().height()));
     //获取窗口的宽度和高度
    widthvalue->setText(QString::number(width()));
    heightvalue->setText(QString::number(height()));
    //作用：获取窗口客户区的矩形信息（相对于窗口自身坐标系）特点：返回的QRect的x和y始终为0，width/height与width()/height()相同
    rectvalue->setText(QString::number(rect().x())+","+QString::number(rect().y())+","+QString::number(width())+","+QString::number(height()));
    //作用：获取窗口客户区的尺寸信息,返回值：QSize对象，包含(width, height)
    sizevalue->setText(QString::number(size().width())+","+QString::number(size().height()));
}


